package view;

import model.Config;

import com.trolltech.qt.gui.QComboBox;
import com.trolltech.qt.gui.QDialog;
import com.trolltech.qt.gui.QHBoxLayout;
import com.trolltech.qt.gui.QLabel;
import com.trolltech.qt.gui.QPushButton;

public class NewMapDialog extends QDialog {

    private final QLabel labelSize;
    private final QLabel labelBuilds;
    private final QComboBox boxNumSize;
    private final QComboBox boxNumBuilds;
    private final QPushButton okButton;

	public NewMapDialog(final MainWindow mainWindow) {		
		super(mainWindow);
		
		setModal(true);
		
		labelSize = new QLabel("Building Size :");
		labelBuilds = new QLabel("Buildings number:");
//        lineEdit = new QLineEdit();
        boxNumSize = new QComboBox();
        
        boxNumSize.addItem("3");
        boxNumSize.addItem("4");
        boxNumSize.addItem("5");
        boxNumSize.addItem("6");
        boxNumSize.addItem("7");
        boxNumSize.addItem("8");
        labelSize.setBuddy(boxNumSize);
        
        boxNumBuilds = new QComboBox();
        
        boxNumBuilds.addItem("1");
        boxNumBuilds.addItem("4");
        boxNumBuilds.addItem("9");
        boxNumBuilds.addItem("16");
        boxNumBuilds.addItem("25");
        labelBuilds.setBuddy(boxNumBuilds);


        boxNumSize.setCurrentIndex(2);
        boxNumBuilds.setCurrentIndex(2);
        
        okButton = new QPushButton("Ok");
        okButton.setDefault(true);
        

        final QHBoxLayout mainLayout = new QHBoxLayout();
        mainLayout.addWidget(labelBuilds);
        mainLayout.addWidget(boxNumBuilds);
        mainLayout.addWidget(labelSize);
        mainLayout.addWidget(boxNumSize);
        mainLayout.addWidget(okButton);

        setLayout(mainLayout);
        


		okButton.clicked.connect(this,"buttonClicked()");
		okButton.clicked.connect(this,"close()");

        setWindowTitle("New Map");
	}
	@SuppressWarnings("unused")
	private void buttonClicked() {
		final int bb = Integer.parseInt(this.boxNumBuilds.currentText());
		final int bs = Integer.parseInt(this.boxNumSize.currentText());
		
//TODO
//		((MainWindow)parent()).setCityMap(new CityMap());
		Config.numPalaces =(int) Math.sqrt((double)bb) ;
		Config.nCellsPalace = bs;
		((MainWindow)parent()).getMenuBarControl().showLabWidget();
		


	}

}
